package com.dorm.cj.dr.demo;

import com.dorm.cj.dr.MyEvent;

import java.util.Calendar;
import java.util.Random;
import java.util.concurrent.TimeUnit;

public class MyConsumer extends AbsEventConsumer<MyEvent> {

    private String name;

    public MyConsumer(String name) {
        this.name = name;
    }

    @Override
    public void consume(MyEvent event) {
        System.out.println(now() + "：拿到队列中的数据：" + event.toString());
        //等待1秒钟
        try {
            TimeUnit.MILLISECONDS.sleep(new Random(100).nextInt());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    // 获取当前时间（分:秒）
    public String now() {
        Calendar now = Calendar.getInstance();
        return "[" + now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND) + "] ";
    }
}
